package com.xb.system.controller;

import com.xb.common.result.Result;
import com.xb.system.service.UsersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author wjh
 * @create 2024-07-22 16:31
 */
@Api(tags = "2、索引创建和删除管理")
@RestController
@RequestMapping("/admin/system/sqlIndex")
public class SqlIndexController {
    
    @Resource
    private UsersService usersService;

    @ApiOperation(value = "创建索引")
    @GetMapping("/create")
    public Result createIndex() {
        try {
            usersService.createIndexes();
            return Result.ok("创建索引成功");
        } catch (Exception e) {
            throw new RuntimeException("已存在相同的索引，不要重复创建");
        }
    }

    @ApiOperation(value = "删除索引")
    @GetMapping("/drop")
    public Result dropIndex() {
        try {
            usersService.dropIndexes();
            return Result.ok("删除索引成功");
        } catch (Exception e) {
            throw new RuntimeException("要删除的索引不存在，可能已经删除");
        }
    }
}
